key= "7bdac67270c803349259a1845da5cdf6"
#地理编码
def geocode(key,address,city=None,batch='false',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
    'key':key,
    'address':address,
    'city':city,
    'batch':batch,
    'sig':sig,
    'output':json,
    'callback':callback
    }
    response=requests.get(url,params=params)
    results=response.json()['geocodes'][0]['location']
    # return
    return results

#逆地理编码
def regeo(key,location,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0'):
    url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
    params = {
        "key":key,
        "location":中大南方_location,
        "extensions":extensions,
        "radius":radius,
        "poitype":poitype
    }
    r = requests.get(url,params)
    results = r.json()
    return results

#路径规划-步行
def walking(key,origin,destination,sig=None,output='json',callback=None):
    #步行路径规划
    url='https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'sig':sig,
        'output':output,
        'callback':callback,
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

#路径规划-公交
def transit(key,origin,destination,city):
    url = "https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params ={
        "key":key,
        "origin":origin,
        "destination":destination,
        "city":city
    }
    r = requests.get(url,params=params)
    result = r.json()
    return result

#路径规划-驾车
def driving(key,origin,destination):
    url='https://restapi.amap.com/v3/direction/driving?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'extensions':extensions
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#路径规划-骑行
def bicycling(key,origin,destination):
    url='https://restapi.amap.com/v4/direction/bicycling?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#路径规划-货车
def truck(key,origin,destination,size):
    url='https://restapi.amap.com/v4/direction/truck?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'size':size
    }
    response=requests.get(url,params)
    results=response.json()
    return results


#路径规划-物流测量矩阵
def route(key,ID,origin,destination):
    url='https://tsapi.amap.com/v1/logistics/route/matrix'
    params={
        'key':key,
        'ID':ID,
        'origin':origin,
        'destination':destination,
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#路径规划-物流长途距离测算
def longmatrix(key,ID,origin,destination):
    url='https://tsapi.amap.com/v1/logistics/route/longmatrix/add'
    params={
        'key':key,
        'ID':ID,
        'origin':origin,
        'destination':destination,
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#路径规划-距离测量
def distance(key,origins,destination,type='0',sig=None,output='json',callback=None):
    #测量距离
    url='https://restapi.amap.com/v3/distance?parameters'
    params={
        'key':key,
        'origins':origins,
        'destination':destination,
        'type':type,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#行政区域查询
def district(key,keywords=None,subdistrict='1',page='1',offset='20',extensions='base',callback=None,output='json'):
    #行政区域查询
    url='https://restapi.amap.com/v3/config/district?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'subdistrict':subdistrict,
        'extensions':extensions,
        'page':page,
        'offset':offset,
        'callback':callback,
        'output':output
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#搜索POI-关键字搜索
def text(key,keywords,city):
    #搜索POI-关键字搜索
    url='https://restapi.amap.com/v3/place/text?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'city':city
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#搜索POI-周边搜索
def around(key,location,keywords):
    #搜索POI-周边搜索
    url='https://restapi.amap.com/v3/place/around?parameters'
    params={
        'key':key,
        'location':location,
        'keywords':keywords
    }
    response=requests.get(url,params)
    results=response.json()
    return results

#搜索POI-多边形搜索
def poly(key,polygon,keywords=None,types=None,offset='20',page='1',extensions='base',sig=None,output='json',callback=None):
    #搜索POI-多边形搜索
    url='https://restapi.amap.com/v3/place/polygon?parameters '
    params={
        'key':key,
        'polygon':polygon,
        'keywords':keywords,
        'types':types,
        'offset':offset,
        'page':page,
        'extensions':extensions,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    results=response.json()
    return results


#搜索POI-ID查询
def detial(key,id,sig=None,output='json',callback=None):
    #搜索POI-ID查询
    url='https://restapi.amap.com/v3/place/detail?parameters'
    params={
        'key':key,
        'id':id,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    results=response.json()
    return results


 #IP定位
def ip(key,ip=None,sig=None,output='json'):
    #IP定位
    url='https://restapi.amap.com/v3/ip?parameters'
    params={
        'key':key,
        'ip':ip,
        'sig':sig,
        'output':output
    }
    response=requests.get(url,params)
    results=response.json()
    return results


#静态地图
def staticmap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic='0',sig=None):
    #获取静态地图信息
    url='https://restapi.amap.com/v3/staticmap?parameters'
    params={
    'key':key,
    'location':location,
    'zoom':zoom,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic,
    'sig':sig
    }
    r=requests.get(url,params)
    data=r.url
    return data


#坐标转换
def convert(key,locations,coordays=None,sig=None,output='json'):
    url='https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    params={
        'key':key,
        "locations":locations,
        'coordays':coordays,
        'sig':sig,
        'output':output
    }
    response=requests.get(url,params)
    r=response.json()
    return r



#天气查询
def weatherInfo(key,city,extensions='base',output='json'):
    url='https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    params={
        'key':key,
        "city":city,
        "extensions":extensions,
        "output":output
    }
    response=requests.get(url,params)
    results=response.json()
    return results

# 输入提示
def inputtips(key,keywords,type=None,location=None,city=None,citylimit='false',datatype=None,sig=None,output='json',callback=None):
    # 输入提示
    url='https://restapi.amap.com/v3/assistant/inputtips?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'type':type,
        'location':location,
        'city':city,
        'citylimit':citylimit,
        'datatype':datatype,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    r=response.json()
    return r


#交通态势
def rec(key,rectangle,level='5',extensions='base',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/traffic/status/rectangle?parameters'
    params={
        'key':key,
        'rectangle':rectangle,
        'level':level,
        'extensions':extensions,
        'sig':sig,
        'output':output,
        'callback':callback,
    }
    response=requests.get(url,params)
    results=response.json()
    return results